package com.ctg.payroll2.action.social;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.ctg.payroll2.bean.filter.social.PbCommsocialMasterFilter;
import com.ctg.payroll2.bean.filter.social.PbSocialMasterFilter;
import com.ctg.payroll2.bean.po.social.CsEmplsocial;
import com.ctg.payroll2.bean.po.social.PbCommsocialMaster;
import com.ctg.payroll2.service.social.RecomTemplateService;
import com.ctg.payroll2.util.Constants;
import com.ctg.platform.util.Page;
import com.ctg.platform.util.Parse;
import com.opensymphony.xwork2.ActionSupport;
/**
 * 推荐社保模板
 * @author 鲁力 2009-9-7 上午09:40:49
 *
 */
public class RecomTemplateAction extends ActionSupport {
	private static final long serialVersionUID = -8854043904122719414L;
	/**
	 * 查询翻页结果
	 */
	private Page result;
	/**
	 * 社保翻页结果
	 */
	private Page socialResult;
	/**
	 * 社保项目ids
	 */
	private String arr;
	/**
	 * 查询条件过滤器
	 */
	private PbCommsocialMasterFilter filter;
	/**
	 * 社保项目查询条件过滤器
	 */
	private PbSocialMasterFilter socialFilter;
	/**
	 * 新增和更新时用到的
	 */
	private PbCommsocialMaster pbCommsocialMaster;
	/**
	 * 用到的service,用spring注入
	 */
	private RecomTemplateService service;
	private String templateIds;
	private String socialSecurityIds;
	private Long socialSecurityId;
	/**
	 * 显示社保列表用到的翻页action
	 * @return
	 */
	public String querySocial(){
		socialResult = service.querySocialItemAll(socialFilter);
		return SUCCESS;
	}
	/**
	 * 页面翻页查询
	 * @return 翻页结果
	 */
	public String query(){
		HttpServletRequest request = ServletActionContext.getRequest();
		if(filter==null){
			filter=new PbCommsocialMasterFilter();
		}
		filter.setStartIndex(Parse.toInteger(request.getParameter("start") , 0));
		filter.setEndIndex(Parse.toInteger(request.getParameter("limit"), Constants.DEFAULT_PAGE_SIZE));
		result = service.queryRecomTemplate(filter);
		return SUCCESS;
	}
	/**
	 * 新增一个推荐社保模板
	 * @return
	 */
	public String insertRecomTemplate(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String adds = request.getParameter("adds");
		List<CsEmplsocial> addsList=new ArrayList<CsEmplsocial>();
		JSONArray modifiedArray = JSONArray.fromObject(adds);
		for (int i = 0; i < modifiedArray.size(); i++) {
			   Object o = modifiedArray.get(i);
			   JSONObject jsonObject = JSONObject.fromObject(o);
			   CsEmplsocial csEmplsocial = (CsEmplsocial) JSONObject.toBean(jsonObject, CsEmplsocial.class);
			   addsList.add(csEmplsocial);
		}
		service.insertRecomTemplate(pbCommsocialMaster);
		return SUCCESS;
	}
	public String updateRecomTemplate(){
		service.updateRecomTemplate(pbCommsocialMaster);
		return SUCCESS;
	}
	/**
	 * 添加一组社保模板
	 * @return
	 */
	public String insertSecutityItem(){
		service.insertPbCommsocialDetail(socialSecurityIds, pbCommsocialMaster.getTemplate_id());
		return SUCCESS;
	}
	/**
	 * 删除推荐模板
	 * @return
	 */
	public String deleteRecomTemplateById(){
		service.deleteRecomTemplateById(pbCommsocialMaster.getTemplate_id());
		return SUCCESS;
	}
	/**
	 * 批量删除推荐模板
	 * @return
	 */
	public String deleterecomTemplateByIds(){
		service.deleteRecomTemplateByIds(templateIds);
		return SUCCESS;
	}
	/**
	 * 批量删除社保项目
	 * @return
	 */
	public String deleteSocialSecurityByIds(){
		service.deletePbCommsocialByIds(this.socialSecurityIds);
		return SUCCESS;
	}
	/**
	 * 删除社保项目
	 * @return
	 */
	public String deleteSocialSecurityById(){
		service.deletePbCommsocialById(socialSecurityId);
		return SUCCESS;
	}
	/**
	 * 复查推荐社保模板
	 * @return
	 */
	public String retrieveEntity(){
		pbCommsocialMaster = service.getPbSocialMasterById(pbCommsocialMaster.getTemplate_id());
		return SUCCESS;
	}
	/**************************************************************
	 * 
	 * getter, setter方法
	 * 
	 *************************************************************/
	/**
	 * @return 返回filter
	 */
	public PbCommsocialMasterFilter getFilter() {
		return filter;
	}
	/**
	 * @param filter 设置filter
	 */
	public void setFilter(PbCommsocialMasterFilter filter) {
		this.filter = filter;
	}
	/**
	 * @return 返回pbCommsocialMaster
	 */
	public PbCommsocialMaster getPbCommsocialMaster() {
		return pbCommsocialMaster;
	}
	/**
	 * @param pbCommsocialMaster 设置pbCommsocialMaster
	 */
	public void setPbCommsocialMaster(PbCommsocialMaster pbCommsocialMaster) {
		this.pbCommsocialMaster = pbCommsocialMaster;
	}
	/**
	 * @return 返回result
	 */
	public Page getResult() {
		return result;
	}
	/**
	 * @param result 设置result
	 */
	public void setResult(Page result) {
		this.result = result;
	}
	/**
	 * @param service 设置service
	 */
	public void setService(RecomTemplateService service) {
		this.service = service;
	}
	/**
	 * @return 返回socialSecurityIds
	 */
	public String getSocialSecurityIds() {
		return socialSecurityIds;
	}
	/**
	 * @param socialSecurityIds 设置socialSecurityIds
	 */
	public void setSocialSecurityIds(String socialSecurityIds) {
		this.socialSecurityIds = socialSecurityIds;
	}
	/**
	 * @return 返回templateIds
	 */
	public String getTemplateIds() {
		return templateIds;
	}
	/**
	 * @param templateIds 设置templateIds
	 */
	public void setTemplateIds(String templateIds) {
		this.templateIds = templateIds;
	}
	/**
	 * @return 返回socialResult
	 */
	public Page getSocialResult() {
		return socialResult;
	}
	/**
	 * @param socialResult 设置socialResult
	 */
	public void setSocialResult(Page socialResult) {
		this.socialResult = socialResult;
	}
	/**
	 * @return 返回socialSecurityId
	 */
	public Long getSocialSecurityId() {
		return socialSecurityId;
	}
	/**
	 * @param socialSecurityId 设置socialSecurityId
	 */
	public void setSocialSecurityId(Long socialSecurityId) {
		this.socialSecurityId = socialSecurityId;
	}
	/**
	 * @return 返回socialFilter
	 */
	public PbSocialMasterFilter getSocialFilter() {
		return socialFilter;
	}
	/**
	 * @param socialFilter 设置socialFilter
	 */
	public void setSocialFilter(PbSocialMasterFilter socialFilter) {
		this.socialFilter = socialFilter;
	}
	/**
	 * @return 返回arr
	 */
	public String getArr() {
		return arr;
	}
	/**
	 * @param arr 设置arr
	 */
	public void setArr(String arr) {
		this.arr = arr;
	}
}
